DAY6:Vowel Count


Posted by birdbirdmurmur on 2023-07-19

題目連結:

Vowel Count

解題思維:

1.將a、e、i、o、u放進陣列
2.設定一個計數器
3.迴圈遍歷字串的每個字
4.如果有在陣列裡面,計數器+1

解法:

function getCount(str) {
  const vowels = ['a', 'e', 'i', 'o', 'u'];
  let count = 0;

  for (let i = 0; i < str.length; i++) {
    if (vowels.includes(str[i])) {
      count++;
    }
  }
  return count;
}

#javascript #Codewars #includes







Related Posts

4. 安裝與使用第三方套件

4. 安裝與使用第三方套件

CDS2019 Next-generation web styling 整理介紹

CDS2019 Next-generation web styling 整理介紹

[筆記]TCL 01 -初學者

[筆記]TCL 01 -初學者


Comments